<template>
  <div class="loginin">
    <div v-if="state == 1">
      <div>
        <el-input
          placeholder="用户名"
          style="width: 500px"
          v-model="user.username"
        >
          <template slot="prepend"
            ><img
              src="@/assets/img/user.png"
              style="width: 30px; height: 30px"
              alt=""
          /></template>
        </el-input>
      </div>
      <div style="margin-top: 30px">
        <el-input
          placeholder="密码"
          type="password"
          style="width: 500px"
          v-model="user.password"
        >
          <template slot="prepend"
            ><img
              src="@/assets/img/password.png"
              style="width: 30px; height: 30px"
              alt=""
          /></template>
        </el-input>
      </div>
      <div style="margin-top: 30px">
        <el-input placeholder="验证码" style="width: 400px" v-model="vcode">
          <template slot="prepend"
            ><img
              src="@/assets/img/vcode.png"
              style="width: 30px; height: 30px"
              alt=""
          /></template>
        </el-input>
        <img
          id="codeimg"
          @click="changeIma"
          src="http://localhost:81/checkCode/re"
        />
      </div>
      <div class="loginbt">
        <el-button type="primary" style="width: 500px" @click="sregist"
          >注册</el-button
        >
      </div>
      <div class="labt">
        <div>
          <el-checkbox v-model="checked"></el-checkbox>
          <h4>
            用户须知
            <p style="color: red">《...协议》</p>
          </h4>
        </div>
        <div style="cursor: pointer" @click="toMregist">注册管理员</div>
      </div>
    </div>
    <!-- <component :is="startName"></component> -->
  </div>
</template>

<script>
import axios from 'axios'
import Header from '../Header.vue'

export default {
  data() {
    return {
      input1: '',
      state: 1,
      user: {
        username: '',
        password: '',
      },
      vcode: '',
      checked: true,
    }
  },
  methods: {
    changeIma() {
      var dt = new Date().getMilliseconds() //获取时间毫秒，使参数不同
      document.getElementById('codeimg').src =
        'http://localhost:81/checkCode/re?' + dt
    },
    //点击注册
    async sregist() {
      const that = this
      if (that.checked === true) {
        const { data: res } = await axios({
          method: 'POST',
          url: 'http://localhost:81/user/regist?vcode=' + that.vcode,
          data: that.user,
        })
        console.log('普通注册返回数据', res)
        if (res.code == 200) {
          that.state = 0
          //注册成功
          that.$emit('Registdata', 'Loginin')
        } else {
          that.$message.error(res.msg)
        }
      }else{
        that.$message.warning("请先勾选用户协议")
      }
    },
    //点击管理员注册
    toMregist() {
      const that = this
      that.$emit('Registdata', 'Mregistin')
    },
  },
  mounted() {},
  components: {
    Header,
  },
}
</script>

<style lang="less" scoped>
.loginin {
  display: flex;
  position: absolute;
  top: 330px;
  right: 350px;
  width: 500px;
  height: 400px;
}
#codeimg {
  width: 90px;
  height: 35px;
  position: absolute;
  border-radius: 5px;
  margin-left: 5px;
}
.loginbt {
  display: flex;
  position: absolute;
  top: 220px;
  right: 0;
}
.labt {
  display: flex;
  width: 100%;
  position: absolute;
  top: 270px;
  justify-content: space-between;
  h4 {
    display: flex;
    position: absolute;
    top: -20px;
    left: 20px;
    p {
      margin-top: -1px;
    }
  }
}
</style>
